<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function test() {
        return new Promise((resolve, reject) => {
          setTimeout(() => resolve("this is test"), 2000);
        }, 1000);
      }
      function test1() {
        return new Promise((resolve, reject) => {
          setTimeout(() => resolve("this is test1"), 2000);
        }, 2000);
      }
      function test2() {
        return new Promise((resolve, reject) => {
          setTimeout(() => resolve("this is test2"), 2000);
        }, 2000);
      }
      function test3() {
        return new Promise((resolve, reject) => {
          setTimeout(() => resolve("this is test3"), 2000);
        }, 2000);
      }

      test()
        .then((data) => {
          console.log("0");
          console.log(data);
          return test1();
        })
        .then((data) => {
          console.log("1");
          console.log(data);
          return test2();
        })
        .then((data) => {
          console.log("2");
          console.log(data);
          return test3();
          console.log("777777");
        })
        .then((data) => {
          console.log("3");
          console.log(data);
        })
        .then((data) => {
          console.log("4");
          console.log(data);
        })
        .then((data) => {
          console.log("5");
          throw new Error("err");
          console.log("55555");
          console.log(data);
        })
        .then((data) => {
          console.log("6");
          console.log(data);
        })
        .catch((err) => {
          console.log("err1");
          console.log(err);
          throw new Error("err");
        })
        .then((data) => {
          console.log("5");
          console.log(data);
        })
        .catch((err) => {
          console.log("err2");
          console.log(err);
        });
    </script>
  </body>
</html>
